package com.main.rentsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.main.rentsystem.pojo.dto.UserPageQueryDTO;
import com.main.rentsystem.pojo.entity.Message;
import com.main.rentsystem.pojo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {


    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getUserById(@Param("id") Long id);

    /**
     * 用户留言
     * @param message
     */
    @Insert("insert into message (content,user_id,post_time) values (#{content},#{userId},#{postTime})")
    void InsertMseeage(Message message);

    /**
     * 查询我的留言
     * @return
     */
    List<Message> GetMessage(User user);

    /**
     * 查询所有注册用户
     * @return
     */
    Page<User> getUserInfo(UserPageQueryDTO userPageQueryDTO);

    /**
     * 批量删除用户
     * @param ids
     */
    void deleteBatch(@Param("ids") List<Long> ids);


    /**
     * 修改密码
     * @param user
     * @param newPassword
     */
    @Update("update user set password = #{newPassword} where id = #{user.id}")
    void changPassword(@Param("user") User user, @Param("newPassword") String newPassword);;
}
